package com.zhongli.devplatform.utils;

import lombok.extern.slf4j.Slf4j;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;

@Slf4j
public class PinYinUtil {
    static HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat();

    static {
        outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
        outputFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
    }

    public static String toHanYuPinyinString(String str) {
        try {
            return PinyinHelper.toHanYuPinyinString(str, outputFormat, "", true);
        } catch (Exception e) {
            log.error(e.getLocalizedMessage());
            return null;
        }

    }


}
